home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / pcb-1.000 / pcb-1 / pcb-1.3 / printpanner.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  9KB  |  336 lines

  1. /*
  2.  *                            COPYRIGHT
  3.  *
  4.  *  PCB, interactive printed circuit board design
  5.  *  Copyright (C) 1994,1995 Thomas Nau
  6.  *
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  *  Contact addresses for paper mail and Email:
  22.  *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
  23.  *  Thomas.Nau@rz.uni-ulm.de
  24.  *
  25.  */
  26.  
  27. static    char    *rcsid = "$Header: /sda4/users/nau/src/pcb/RCS/printpanner.c,v 2.3 1994/10/29 17:27:15 nau Exp $";
  28.  
  29. /* print dialog panner routines
  30.  * only available for X11R5 and later
  31.  * all routines are defined 'empty' for X11R4
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <ctype.h>
  37. #include <X11/Xlib.h>
  38.  
  39. #include "global.h"
  40.  
  41. #include "data.h"
  42. #include "menu.h"
  43. #include "misc.h"
  44. #include "printpanner.h"
  45.  
  46. /* ---------------------------------------------------------------------------
  47.  * some local types
  48.  */
  49. typedef struct                    /* media description */
  50. {
  51.     String        Name;            /* name and size (in mil) */
  52.     Dimension    Width,
  53.                 Height;
  54. } MediaType, *MediaTypePtr;
  55.  
  56. /* ---------------------------------------------------------------------------
  57.  * some local identifiers
  58.  */
  59. static    int                Index = -1;        /* media index */
  60. static    MediaType        Media[] = {        /* first one is user defined */
  61.     { "user defined", 0, 0 },
  62.     { "a3", 11690, 16530 },
  63.     { "a4", 8260, 11690 },
  64.     { "a5", 5830, 8260 },
  65.     { "letter", 8500, 11000 },
  66.     { "tabloit", 11000, 17000 },
  67.     { "ledger", 17000, 11000 },
  68.     { "legal", 8500, 14000 },
  69.     { "executive", 7500, 10000 },
  70.     { NULL, 0, 0 }};
  71. static    PopupEntryType    MediaMenuEntries[ENTRIES(Media)+1];
  72. static    PopupMenuType    MediaMenu =
  73.     { "media", NULL, MediaMenuEntries, NULL, NULL, NULL };
  74. static    MenuButtonType    MediaMenuButton =
  75.     { "media", "Media", &MediaMenu, NULL };
  76.  
  77. /* ---------------------------------------------------------------------------
  78.  * a local prototype for both cases
  79.  */
  80. static    void    InitDefaultMedia(void);
  81.  
  82. /***************************************************************************** 
  83.  * routines for X11R5 an newer
  84.  *****************************************************************************/
  85. #if XlibSpecificationRelease >= 5
  86.  
  87. #include <X11/Xaw/Form.h>
  88. #include <X11/Xaw/Label.h>
  89. #include <X11/Xaw/Panner.h>
  90.  
  91. /* ---------------------------------------------------------------------------
  92.  * some local prototypes
  93.  */
  94. static    void    CB_Media(Widget, XtPointer, XtPointer);
  95. static    Widget    PrintPannerCreateMediaMenu(Widget, Widget, Widget);
  96.  
  97. /* ---------------------------------------------------------------------------
  98.  * some local identifiers
  99.  */
  100. static    Widget            Panner,            /* the panner widget */
  101.                         SizeField;        /* label to display the media size */
  102. static    Dimension        Width, Height;    /* layout size */
  103.  
  104. /* ---------------------------------------------------------------------------
  105.  * updates the panner widget
  106.  */
  107. void PrintPannerUpdate(float Scale, Boolean RotateFlag)
  108. {
  109.     Dimension    width, height;
  110.  
  111.         /* scale layout size */
  112.     width = (Dimension) ((float) Width *Scale);
  113.     height = (Dimension) ((float) Height *Scale);
  114.  
  115.         /* update slider */
  116.     XtVaSetValues(Panner,
  117.         XtNsliderWidth, RotateFlag ? height : width,
  118.         XtNsliderHeight, RotateFlag ? width : height,
  119.         NULL);
  120. }
  121.  
  122. /* ---------------------------------------------------------------------------
  123.  * callback for media size selection (menu)
  124.  */
  125. static void CB_Media(Widget W, XtPointer ClientData, XtPointer CallData)
  126. {
  127.     MediaTypePtr    media = &Media[(int) ClientData];
  128.     char            size[128];
  129.     Dimension        mediawidth,
  130.                     mediaheight;
  131.  
  132.         /* set visible size of media, use global identifiers because
  133.          * the size will also be used in printdialog.c
  134.          */
  135.     Settings.MediaWidth = media->Width;
  136.     Settings.MediaHeight = media->Height;
  137.     mediawidth = Settings.MediaWidth -2*Settings.MediaMarginLeft;
  138.     mediaheight = Settings.MediaHeight -2*Settings.MediaMarginBottom;
  139.  
  140.     sprintf(size, "media size:     %4.2f\" x %4.2f\"\n"
  141.                   "without margin: %4.2f\" x %4.2f\"\n",
  142.         (float) Settings.MediaWidth /1000.0,
  143.         (float) Settings.MediaHeight /1000.0,
  144.         (float) mediawidth /1000.0,
  145.         (float) mediaheight /1000.0);
  146.  
  147.         /* update widgets */
  148.     XtVaSetValues(SizeField, XtNlabel, size, NULL);
  149.     XtVaSetValues(Panner,
  150.         XtNcanvasHeight, mediaheight,
  151.         XtNcanvasWidth, mediawidth,
  152.         NULL);
  153. }
  154.  
  155. /* ---------------------------------------------------------------------------
  156.  * creates 'media size' menu
  157.  */
  158. static Widget PrintPannerCreateMediaMenu(Widget Parent, Widget Top, Widget Left)
  159. {
  160.     int        i;
  161.  
  162.         /* copy media description to menuentry structure */
  163.     for (i = 0; i < ENTRIES(Media); i++)
  164.     {
  165.         MediaMenuEntries[i].Name = Media[i].Name;
  166.         MediaMenuEntries[i].Label = Media[i].Name;
  167.         MediaMenuEntries[i].Callback = CB_Media;
  168.         MediaMenuEntries[i].ClientData = (char *) i;
  169.         MediaMenuEntries[i].W = NULL;
  170.     }
  171.     return(InitMenuButton(Parent, &MediaMenuButton, Top, Left));
  172. }
  173.  
  174. /* ---------------------------------------------------------------------------
  175.  * creates a print command dialog
  176.  */
  177. Widget PrintPannerCreate(Widget Parent, Widget Top, Widget Left)
  178. {
  179.     Widget        label,
  180.                 menu;
  181.     BoxTypePtr    box;
  182.  
  183.         /* init media size if called the first time */
  184.     if (Index == -1)
  185.         InitDefaultMedia();
  186.  
  187.     label = XtVaCreateManagedWidget("comment", labelWidgetClass,
  188.         Parent,
  189.         LAYOUT_TOP,
  190.         XtNfromVert, Top,
  191.         XtNfromHoriz, Left,
  192.         XtNlabel, "select media and offsets:",
  193.         NULL);
  194.     menu = PrintPannerCreateMediaMenu(Parent, label, Left);
  195.     SizeField = XtVaCreateManagedWidget("sizeField", labelWidgetClass,
  196.         Parent,
  197.         LAYOUT_TOP,
  198.         XtNfromVert, menu,
  199.         XtNfromHoriz, Left,
  200.         XtNlabel, "",
  201.         NULL);
  202.     Panner = XtVaCreateManagedWidget("panner", pannerWidgetClass,
  203.         Parent,
  204.         LAYOUT_TOP,
  205.         XtNdefaultScale, 1,
  206.         XtNfromVert, Top,
  207.         XtNfromHoriz, SizeField,
  208.         XtNrubberBand, True,
  209.         XtNresizable, True,
  210.         NULL);
  211.  
  212.         /* get layout size and initialize size label;
  213.          * layout has already be checked to be non-empty
  214.          */
  215.     box = GetDataBoundingBox(PCB->Data);
  216.     Width = box->X2 -box->X1;
  217.     Height = box->Y2 -box->Y1;
  218.     CB_Media(NULL, (XtPointer) Index, NULL);
  219.     return(Panner);
  220. }
  221.  
  222. /* ----------------------------------------------------------------------
  223.  * return the selected offset and height of slider
  224.  */
  225. void PrintPannerGetOffset(Position *OffsetX, Position *OffsetY)
  226. {
  227.     XtVaGetValues(Panner,
  228.         XtNsliderX, OffsetX,
  229.         XtNsliderY, OffsetY,
  230.         NULL);
  231. }
  232.  
  233. /* ----------------------------------------------------------------------
  234.  * set the panner offset
  235.  */
  236. void PrintPannerSetSliderPosition(Position OffsetX, Position OffsetY)
  237. {
  238.     XtVaSetValues(Panner,
  239.         XtNsliderX, OffsetX,
  240.         XtNsliderY, OffsetY,
  241.         NULL);
  242. }
  243.  
  244. #else
  245.  
  246. /***************************************************************************** 
  247.  * routines for X11R4 an older; just some empty routines
  248.  *****************************************************************************/
  249. void PrintPannerUpdate(float Scale, Boolean RotateFlag)
  250. {
  251. }
  252.  
  253. Widget PrintPannerCreate(Widget Parent, Widget Top, Widget Left)
  254. {
  255.     if (Index == -1)
  256.         InitDefaultMedia();
  257.     Settings.MediaWidth = Media[Index].Width;
  258.     Settings.MediaHeight = Media[Index].Height;
  259.     return(Top);
  260. }
  261.  
  262. void PrintPannerSetSliderPosition(Position OffsetX, Position OffsetY)
  263. {
  264. }
  265.  
  266. void PrintPannerGetOffset(Position *OffsetX, Position *OffsetY)
  267. {
  268.         /* always pass zero as offset */
  269.     *OffsetX = 0;
  270.     *OffsetY = 0;
  271. }
  272.  
  273. #endif
  274.  
  275. /***************************************************************************** 
  276.  * routines common to all X releases
  277.  *****************************************************************************/
  278. /* ---------------------------------------------------------------------------
  279.  * initializes the user defined mediasize and sets it as default
  280.  * only called once
  281.  */
  282. static void InitDefaultMedia(void)
  283. {
  284.     int                i,
  285.                     x, y;
  286.     unsigned int    width, height;
  287.     char            *p1, *p2;
  288.  
  289.         /* check if the passed string is equal to a known media type
  290.          * first entry is user defined, last one holds a zero pointer only
  291.          */
  292.     for (i = 1; i < ENTRIES(Media)-1; i++)
  293.     {
  294.         p1 = Media[i].Name;
  295.         p2 = Settings.Media;
  296.  
  297.             /* ignore case */
  298.         for (; *p1 && *p2 && (tolower(*p1) == tolower(*p2)); p1++, p2++);
  299.  
  300.             /* found a match */
  301.         if (*p1 == *p2)
  302.             break;
  303.     }
  304.  
  305.     if (i != ENTRIES(Media)-1)
  306.     {
  307.             /* used the found entry */
  308.         Index = i;
  309.         width = Media[i].Width;
  310.         height = Media[i].Height;
  311.     }
  312.     else
  313.     {
  314.             /* no match, try to evaluate it as geometry string;
  315.              * use first entry (user defined)
  316.              */
  317.         Index = 0;
  318.         i = XParseGeometry(Settings.Media, &x, &y, &width, &height);
  319.  
  320.             /* check the syntax */
  321.         if (!(i & WidthValue) || !(i & HeightValue) ||
  322.             (i & XValue) || (i & YValue))
  323.         {
  324.                 /* failed; use default setting (a4) */
  325.             width = 8260;
  326.             height = 11690;
  327.         }
  328.     }
  329.  
  330.         /* set size as user default; 'Index' is already set to != -1
  331.          * to make sure that routine wont be called again
  332.          */
  333.     Media[0].Width = width;
  334.     Media[0].Height = height;
  335. }
  336.